package com.atguigu.day02;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author mqx
 * @date 2021-4-6 15:31:23
 */
public class MyThreadPoolDemo06 {

    public static void main(String[] args) {

            /*
                下面是三个实现类
                    我们演示他们的区别
             */
        //ExecutorService threadPool  = Executors.newFixedThreadPool(3);
        //ExecutorService threadPool  = Executors.newSingleThreadExecutor();

          ExecutorService threadPool = Executors.newCachedThreadPool();

        /*
            //以前开启开启线程的方式
            for (int i = 1; i <= 10; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"\t 办理业务");
            },String.valueOf(i)).start();
        }
         */


        //  十个顾客,使用线程池开启多线程
        for (int i = 1; i <=100 ; i++) {
            threadPool.execute(()->{
                System.out.println(Thread.currentThread().getName()+"\t 办理业务");
            });
        }

    }
}
